<?php include template('header','common');?>
<link rel="stylesheet" type="text/css" href="{__ROOT__}template/default/statics/css/guanli-detail.css?v={HD_VERSION}">

<div class="container">
	<form class="padding-small" method="post" action='{url("add",array("formhash"=>FORMHASH))}' name="checkmobile">
	<div class="head" id="file-avatars">
    	<div style="position:relative; width: 100px; margin: 0 auto;">
		<img src="{if $student['head']}{$student['head']}{else}{__ROOT__}template/default/statics/images/member/default_head.png{/if}" alt="">
        <div id="headtext" style="height: 50px; width:60px; position:absolute; font-size:14px; top:39px; left:20px;">上传孩子头像用于点名</div>
        </div>
	</div>	
	<div class="content">
		<div class="list">
			<div class="item">
				<img src="{__ROOT__}template/default/statics/img/xue-sheng-xing-ming-.png" alt="">
				<span><input type="text" name="truename" value="{$student['truename']}" placeholder="请填写真实姓名" /></span>
			</div>
			<div class="item">
				<img src="{SKIN_PATH}statics/img/xue-sheng-xing-ming-.png" alt="">
				<select name="sex">
					<option value="0">请选择性别</option>	
					<option value="1" {if $student['sex'] == 1}selected="selected"{/if}>男</option>	
					<option value="2" {if $student['sex'] == 2}selected="selected"{/if}>女</option>
				</select>
			</div>
			<div class="item">
				<img src="{__ROOT__}template/default/statics/img/diqu-.png" alt="">
				
				<select name="area">
					<option value="">请选择所在区域</option>		
					<?php foreach($areas as $k => $v){?>
						<?php if($v['area'] == $student['area']){?>
						<option value="{$v['area']}" selected="selected">{$v['area']}</option>
						<?php }else{?>
						<option value="{$v['area']}">{$v['area']}</option>
						<?php }?>
					<?php }?>		
				</select>
				
			</div>
			<div class="item">
				<img src="{__ROOT__}template/default/statics/img/xue-xiao-1.png" alt="">				
				<select name="school_id">
					<option value="">请选择所在学校</option>						
				</select>				
			</div>
			<div class="item">
				<img src="{__ROOT__}template/default/statics/img/xue-xiao-nian-ji-.png" alt="">
				<input type="text" name="class_name" value="{$student['class_name']}" placeholder="请填班级，格式：203表示二年级3班">
			</div>
			<div class="item">
				<img src="{__ROOT__}template/default/statics/img/lao-shi-ming-zi-.png" alt="">
				<input type="text" name="teacher_name" value="{$student['teacher_name']}" placeholder="请输入校内紧急联络人，建议为班主任">
			</div>
			<div class="item">
				<img src="{__ROOT__}template/default/statics/img/lao-shi-dian-hua-.png" alt="">
				<input type="text" name="teacher_mobile" value="{$student['teacher_mobile']}" placeholder="请输入联络人电话">
				<input type="hidden" name="head">
			</div>
		</div>
	</div>
	<input type="hidden" name="id" value="{$student['id']}" >
	<div class="btn-view">
		{if $type == 1}
		<button class="btn2" style="width:80%;">添加</button>
		{else}
		<!--button class="btn1" type="button">删除</button-->
		<button class="btn2" style="width:80%;">修改</button>
		{/if}
	</div>
	</form>
</div>
<link type="text/css" rel="stylesheet" href="{__ROOT__}statics/js/upload/uploader.css?v={HD_VERSION}" />
<script type="text/javascript" src="{__ROOT__}statics/js/upload/uploader.js?v={HD_VERSION}"></script>
<script>
var school_id = <?php echo intval($student['school_id']);?>;
getSchool($("[name='area']").val());
$("[name='area']").change(function(){
	getSchool($(this).val());
});

$(".btn2").click(function(){
	if($("input[name=truename]").val() == ''){
		alerts('请填写真实姓名');
		$("input[name=truename]").focus();
		return false;
	}
	if($("select[name=sex]").val() == 0){
		alerts('请选择性别');
		$("select[name=sex]").focus();
		return false;
	}
	if($("select[name=area]").val() == ''){
		alerts('请选择所在区域');
		$("select[name=area]").focus();
		return false;
	}
	if($("select[name=school_id]").val() == ''){
		alerts('请选择学校');
		$("select[name=school_id]").focus();
		return false;
	}
	if($("input[name=class_name]").val() == ''){
		alerts('请填班级，格式：203表示二年级3班');
		$("input[name=class_name]").focus();
		return false;
	}			
	var pattern = /^\d{1}[01]\d{1}$/; 
	if(pattern.test($("input[name=class_name]").val())  == false){
		alerts('班级格式错误，如：203表示二年级3班');
		$("input[name=class_name]").focus();
		return false;
	}
	
	var reg = /^(1(([35][0-9])|(47)|[7][0678]|[8][0123456789]))\d{8}$/;
	if($("input[name=teacher_mobile]").val() && $("input[name=teacher_mobile]").val().match(reg) ==null){
		alerts('您输入的电话格式不正确!');
		return false;
	}
});
function getSchool(area){
	var ajaxurl="<?php echo url('school/index/getSchool')?>";
	var _html = '<option value="">请选择所在学校</option>';
	$.post(ajaxurl,{'area':area},function(data){
		var list = data.result;
		$.each(list, function(i, v) {
			if(school_id == v.id){
				_html += '<option value="'+v.id+'" selected="selected">'+v.name+'</option>';
			}else{
				_html += '<option value="'+v.id+'">'+v.name+'</option>';
			}
		});
		$("[name='school_id']").html(_html);
	},'json');
}
$(".btn1").click(function(){
	var id = $("[name='id']").val();
	var ajaxurl="<?php echo url('member/student/delete')?>";
	$.post(ajaxurl,{'id':id},function(ret){
		if(ret.status == 1){
			alerts(ret.message,1,ret.referer);
		}else{
			alerts(ret.message);
		}
	},'json');
});
var uploader = WebUploader.create({
		auto:true,
		fileVal:'upfile',
		// swf文件路径
		swf: '{__ROOT__}statics/js/upload/uploader.swf',
		// 文件接收服务端。
		server: "<?php echo url('attachment/index/upload')?>",
		// 选择文件的按钮。可选
		formData:{
			file : 'upfile',
			upload_init : '<?php echo $attachment_init ?>'
		},
		quality: 80,
		// 压缩图片大小
		compress:{
			width: 408,
			height: 408,
			allowMagnify: false
		},
		// 内部根据当前运行是创建，可能是input元素，也可能是flash.
		pick: {
			id: '#file-avatars',
			multiple:false
		},
		accept:{
			title: '图片文件',
			extensions: 'gif,jpg,jpeg,bmp,png',
			mimeTypes: 'image/*'
		},
		chunked: false,
		chunkSize:1000000,
		resize: false
	});
	uploader.onFileQueued = function(file){
		alerts("图片上传中...", 3);
	}
	uploader.onUploadError = function(file,reason){
		alerts("图片上传失败");
	}
	uploader.onUploadSuccess = function(file, response) {
		if(response.status == 1) {
			alerts("图片上传成功");
			
			var ajaxurl="<?php echo url('member/student/head')?>";
			$.post(ajaxurl,{'head':response.result.url,w:response.result.width,h:response.result.height},function(ret){
				if(ret.status == 1){
					$("#headtext").hide();
					$(".head").find('img').attr("src", '{__ROOT__}'+ret.result);
					$("input[name=head]").attr("value", ret.result);
				}
			},'json');
		} else {
			alerts(response.message);
		}
	}
</script>
<?php include template('footer','common');?>